package com.qiujie.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiujie.dto.Response;
import com.qiujie.dto.ResponseDTO;
import com.qiujie.entity.Config;
import com.qiujie.entity.Dept;
import com.qiujie.entity.Examine;
import com.qiujie.entity.Staff;
import com.qiujie.enums.AuditStatusEnum;
import com.qiujie.mapper.DeptMapper;
import com.qiujie.mapper.ExamineMapper;
import com.qiujie.mapper.StaffMapper;
import com.qiujie.vo.ConfigVO;
import com.qiujie.vo.ExamineVO;
import com.qiujie.vo.StaffLeaveVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ExamineService extends ServiceImpl<ExamineMapper, Examine> {
    @Resource
    private ExamineMapper examineMapper;
    @Resource
    private StaffMapper staffMapper;
    public ResponseDTO add(Examine examine) {
        if (save(examine)) {
            return Response.success();
        }
        return Response.error();
    }

    public ResponseDTO getExamine(Examine examine) {
        QueryWrapper<Examine> wrapper = new QueryWrapper<>();

        Staff staff = new Staff();
        staff = staffMapper.selectById(examine.getId());

        List<Examine> configList = examineMapper.selectList(wrapper);
        List<ExamineVO> examineVOList = new ArrayList<>();
        Map<Integer,Map<Date, List<Examine>>> examineMap = configList.stream()
                .filter(Objects::nonNull)
                .collect(Collectors.groupingBy(Examine::getUserId,
                        Collectors.groupingBy(Examine::getConfigTime)));
        for (Map.Entry<Integer, Map<Date, List<Examine>>> entry : examineMap.entrySet()) {
            Map<Date, List<Examine>> examineList = entry.getValue();
            for (Map.Entry<Date, List<Examine>> entry2 : examineList.entrySet()) {
                ExamineVO examineVO = new ExamineVO();
                List<Examine> examineList2 = entry2.getValue();
                for (int i = 0; i < examineList2.size(); i++) {
                    // 处理每个Examine对象
                    Examine examine1 = examineList2.get(i);
                    examineVO.setId(examine1.getId());
                    examineVO.setUserId(examine1.getUserId());
                    examineVO.setUserName(examine1.getUserName());
                    examineVO.setStaff(staffMapper.selectById(examine1.getUserId()));
                    examineVO.setConfigTime(examine1.getConfigTime());
                    if (i == 0) {
                        examineVO.setConfigName1(examine1.getConfigName());
                        examineVO.setConfigRate1(examine1.getConfigRate());
                    }
                    if (i == 1) {
                        examineVO.setConfigName2(examine1.getConfigName());
                        examineVO.setConfigRate2(examine1.getConfigRate());
                    }
                    if (i == 2) {
                        examineVO.setConfigName3(examine1.getConfigName());
                        examineVO.setConfigRate3(examine1.getConfigRate());
                    }
                    if (i == 3) {
                        examineVO.setConfigName4(examine1.getConfigName());
                        examineVO.setConfigRate4(examine1.getConfigRate());
                    }
                    if (i == 4) {
                        examineVO.setConfigName5(examine1.getConfigName());
                        examineVO.setConfigRate5(examine1.getConfigRate());
                    }
                    if (i == 5) {
                        examineVO.setConfigName6(examine1.getConfigName());
                        examineVO.setConfigRate6(examine1.getConfigRate());
                    }
                    if (i == 6) {
                        examineVO.setConfigName7(examine1.getConfigName());
                        examineVO.setConfigRate7(examine1.getConfigRate());
                    }
                    if (i == 7) {
                        examineVO.setConfigName8(examine1.getConfigName());
                        examineVO.setConfigRate8(examine1.getConfigRate());
                    }
                    if (i == 8) {
                        examineVO.setConfigName9(examine1.getConfigName());
                        examineVO.setConfigRate9(examine1.getConfigRate());
                    }
                    if (i == 9) {
                        examineVO.setConfigName10(examine1.getConfigName());
                        examineVO.setConfigRate10(examine1.getConfigRate());
                    }
                    if (i == 10) {
                        examineVO.setConfigName11(examine1.getConfigName());
                        examineVO.setConfigRate11(examine1.getConfigRate());
                    }
                    if (i == 11) {
                        examineVO.setConfigName12(examine1.getConfigName());
                        examineVO.setConfigRate12(examine1.getConfigRate());
                    }
                    if (i == 12) {
                        examineVO.setConfigName13(examine1.getConfigName());
                        examineVO.setConfigRate13(examine1.getConfigRate());
                    }
                    if (i == 13) {
                        examineVO.setConfigName14(examine1.getConfigName());
                        examineVO.setConfigRate14(examine1.getConfigRate());
                    }
                    if (i == 14) {
                        examineVO.setConfigName15(examine1.getConfigName());
                        examineVO.setConfigRate15(examine1.getConfigRate());
                    }
                    if (i == 15) {
                        examineVO.setConfigName16(examine1.getConfigName());
                        examineVO.setConfigRate16(examine1.getConfigRate());
                    }
                    if (i == 16) {
                        examineVO.setConfigName17(examine1.getConfigName());
                        examineVO.setConfigRate17(examine1.getConfigRate());
                    }
                    if (i == 17) {
                        examineVO.setConfigName18(examine1.getConfigName());
                        examineVO.setConfigRate18(examine1.getConfigRate());
                    }
                    if (i == 18) {
                        examineVO.setConfigName19(examine1.getConfigName());
                        examineVO.setConfigRate19(examine1.getConfigRate());
                    }
                    if (i == 19) {
                        examineVO.setConfigName20(examine1.getConfigName());
                        examineVO.setConfigRate20(examine1.getConfigRate());
                    }
                    if (i == 20) {
                        examineVO.setConfigName21(examine1.getConfigName());
                        examineVO.setConfigRate21(examine1.getConfigRate());
                    }
                    if (i == 21) {
                        examineVO.setConfigName22(examine1.getConfigName());
                        examineVO.setConfigRate22(examine1.getConfigRate());
                    }
                    if (i == 22) {
                        examineVO.setConfigName23(examine1.getConfigName());
                        examineVO.setConfigRate23(examine1.getConfigRate());
                    }
                    if (i == 23) {
                        examineVO.setConfigName24(examine1.getConfigName());
                        examineVO.setConfigRate24(examine1.getConfigRate());
                    }
                    if (i == 24) {
                        examineVO.setConfigName25(examine1.getConfigName());
                        examineVO.setConfigRate25(examine1.getConfigRate());
                    }
                    if (i == 25) {
                        examineVO.setConfigName26(examine1.getConfigName());
                        examineVO.setConfigRate26(examine1.getConfigRate());
                    }
                    if (i == 26) {
                        examineVO.setConfigName27(examine1.getConfigName());
                        examineVO.setConfigRate27(examine1.getConfigRate());
                    }
                    if (i == 27) {
                        examineVO.setConfigName28(examine1.getConfigName());
                        examineVO.setConfigRate28(examine1.getConfigRate());
                    }
                    if (i == 28) {
                        examineVO.setConfigName29(examine1.getConfigName());
                        examineVO.setConfigRate29(examine1.getConfigRate());
                    }
                    if (i == 29) {
                        examineVO.setConfigName30(examine1.getConfigName());
                        examineVO.setConfigRate30(examine1.getConfigRate());
                    }
                    if (i == 30) {
                        examineVO.setConfigName31(examine1.getConfigName());
                        examineVO.setConfigRate31(examine1.getConfigRate());
                    }
                    if (i == 31) {
                        examineVO.setConfigName32(examine1.getConfigName());
                        examineVO.setConfigRate32(examine1.getConfigRate());
                    }
                    if (i == 32) {
                        examineVO.setConfigName33(examine1.getConfigName());
                        examineVO.setConfigRate33(examine1.getConfigRate());
                    }
                    if (i == 33) {
                        examineVO.setConfigName34(examine1.getConfigName());
                        examineVO.setConfigRate34(examine1.getConfigRate());
                    }
                    if (i == 34) {
                        examineVO.setConfigName35(examine1.getConfigName());
                        examineVO.setConfigRate35(examine1.getConfigRate());
                    }
                    if (i == 35) {
                        examineVO.setConfigName36(examine1.getConfigName());
                        examineVO.setConfigRate36(examine1.getConfigRate());
                    }
                    if (i == 36) {
                        examineVO.setConfigName37(examine1.getConfigName());
                        examineVO.setConfigRate37(examine1.getConfigRate());
                    }
                    if (i == 37) {
                        examineVO.setConfigName38(examine1.getConfigName());
                        examineVO.setConfigRate38(examine1.getConfigRate());
                    }
                    if (i == 38) {
                        examineVO.setConfigName39(examine1.getConfigName());
                        examineVO.setConfigRate39(examine1.getConfigRate());
                    }
                    if (i == 39) {
                        examineVO.setConfigName40(examine1.getConfigName());
                        examineVO.setConfigRate40(examine1.getConfigRate());
                    }
                    if (i == 40) {
                        examineVO.setConfigName41(examine1.getConfigName());
                        examineVO.setConfigRate41(examine1.getConfigRate());
                    }
                    if (i == 41) {
                        examineVO.setConfigName42(examine1.getConfigName());
                        examineVO.setConfigRate42(examine1.getConfigRate());
                    }
                    if (i == 42) {
                        examineVO.setConfigName43(examine1.getConfigName());
                        examineVO.setConfigRate43(examine1.getConfigRate());
                    }
                    if (i == 43) {
                        examineVO.setConfigName44(examine1.getConfigName());
                        examineVO.setConfigRate44(examine1.getConfigRate());
                    }
                    if (i == 44) {
                        examineVO.setConfigName45(examine1.getConfigName());
                        examineVO.setConfigRate45(examine1.getConfigRate());
                    }
                    if (i == 45) {
                        examineVO.setConfigName46(examine1.getConfigName());
                        examineVO.setConfigRate46(examine1.getConfigRate());
                    }
                    if (i == 46) {
                        examineVO.setConfigName47(examine1.getConfigName());
                        examineVO.setConfigRate47(examine1.getConfigRate());
                    }
                    if (i == 47) {
                        examineVO.setConfigName48(examine1.getConfigName());
                        examineVO.setConfigRate48(examine1.getConfigRate());
                    }
                    if (i == 48) {
                        examineVO.setConfigName49(examine1.getConfigName());
                        examineVO.setConfigRate49(examine1.getConfigRate());
                    }
                    if (i == 49) {
                        examineVO.setConfigName50(examine1.getConfigName());
                        examineVO.setConfigRate50(examine1.getConfigRate());
                    }


                }
                examineVOList.add(examineVO);
            }
        }
        return Response.success(examineVOList);
    }
}

